import { DB } from "@/api/sql.ts";

export interface LayerDto {
  name: string;
  parentId: number | null;
  custom: 0 | 1; //1是自定义，表示数据采集
  type: "folder" | "layer";
  remark: string | null;
  weight: number | null;
}

export const addLayer = (data: LayerDto) => {
  return new Promise((resolve, reject) => {
    plus.sqlite.selectSql({
      name: DB,
      sql: `INSERT INTO layer (name, type, parentId, custom, remark, weight) 
        VALUES ('${data.name}', '${data.type}', ${data.parentId}, ${data.custom}, '${data.remark}', ${data.weight});`,
      success(e: any) {
        console.log(e);
        resolve(e);
      },
      fail(e: any) {
        console.log(e);
        reject(e);
      },
    });
  });
};
